<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateComponentProductTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('component_product', function (Blueprint $table) {
            $table->increments('id');
            $table->dateTime('created_at')->comment('创建时间');
            $table->dateTime('updated_at')->default(DB::raw('current_timestamp on update current_timestamp'))->comment('更新时间');
            $table->tinyInteger('enable')->default(1)->comment('是否启用 1[启用] 0[停用]');
            $table->string('position', 30)->comment('组件位置');
            $table->unsignedInteger('product_id')->comment('商品ID');
            $table->integer('sort')->default(0)->comment('排序');
            $table->index('created_at');
            $table->index('position');
            $table->index('product_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('component_product');
    }
}
